<?php
/**
 * QFrameWork
 *
 * @author: quyang
 * @date: 2010-1-17
 * @version: 1.0
 */


class Logger
{
    /**
     * 写入调试LOG
     *
     * @param string $dir
     * @param string $suffix
     * @param string $content
     */
	static public function debug($dir, $content , $suffix = '' ){
	    if(!CORE_ENABLE_FILE_LOG){
			return true;
	    }
		$dir = CORE_LOG_PATH.'debug'.DELIMITER.$dir;
		if(!is_dir($dir)){
		    mkdir($dir , '744' , true);
		}
		$content .= TAB.TAB.date('H:i:s').TAB.TAB.$_SERVER['REQUEST_URI'];
		self::_write($dir , $suffix , $content);
	}
	/**
     * Write Alert log
     *
     * @param string $dir
     * @param string $suffix
     * @param string $content
     */
	static public function alert($type , $where , $error)
	{
		$dir = CORE_LOG_PATH;
		$content = time().' '.$type.TAB.TAB.$where.' '.$error;
		$content .= TAB.date('H:i:s').TAB.TAB.$_SERVER['REQUEST_URI'];
		
		$suffix = 'alert';
		self::_write($dir , $suffix , $content);
	}
	/**
	 * Write API log
	 *
	 * @param string $content
	 * @param string $suffix
	 */
	static public function api($content , $suffix=''){
		$dir = CORE_LOG_PATH.'api'.DELIMITER;
		$content = time().TAB.$content.TAB.date('H:i:s').TAB.$_SERVER['REQUEST_URI'];
		self::_write($dir , $suffix , $content);
	}
	/**
	 * 写入LOG
	 *
	 * @param string $dir
	 * @param string $suffix
	 * @param string $content
	 */
	static private function _write($dir , $suffix , $data){
		$file = $dir.'/'.date('Y-m-d').($suffix ? '_'.$suffix : '').'.log';
		file_put_contents($file , $data.NL , FILE_APPEND);
		return ;
	}
}
?>